package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.LeaseSourceType;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.ApartmentInfoService;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.atguigu.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    private RoomInfoMapper  roomInfoMapper;
    @Autowired
    private PaymentTypeMapper paymentTypeMapper;
    @Autowired
    private LeaseTermMapper leaseTermMapper;
    @Override
    public IPage<AgreementVo> getAgreementVoPage(Page<AgreementVo> agreementVoPage, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.getAgreementVoPage(agreementVoPage, queryVo);
    }

    @Override
    public AgreementVo getAgreementVoById(Long id) {
        //获取租约信息
        LeaseAgreement byId = this.getById(id);
        AgreementVo agreementVo = new AgreementVo();
        //属性对拷
        BeanUtils.copyProperties(byId, agreementVo);
        //获取公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(byId.getApartmentId());
        agreementVo.setApartmentInfo(apartmentInfo);
        //获取房间信息
        RoomInfo roomInfo = roomInfoMapper.selectById(byId.getRoomId());
        agreementVo.setRoomInfo(roomInfo);
        //获取支付类型信息
        PaymentType paymentType = paymentTypeMapper.selectById(byId.getPaymentTypeId());
        agreementVo.setPaymentType(paymentType);
        //获取租期信息
        LeaseTerm leaseTerm = leaseTermMapper.selectById(byId.getLeaseTermId());
        agreementVo.setLeaseTerm(leaseTerm);
        //返回
        return agreementVo;

    }


}




